using System;

namespace CHEnhanceEfCore.Common
{
    public class Result
    {
        public int code { get; set; }
        public string msg { get; set; }
        public Object data { get; set; }

        private Result()
        {
        }

        /// <summary>
        /// 成功时调用
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static Result success(Object data = null)
        {
            Result result = new Result
            {
                code = 200,
                msg = "success"
            };
            if (null != data)
            {
                result.data = data;
            }

            return result;
        }

        /// <summary>
        /// 失败时调用
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static Result fail(string msg = null)
        {
            Result result = new Result
            {
                code = 500,
                msg = "server error"
            };
            if (null != msg)
            {
                result.msg = msg;
            }

            return result;
        }
    }
}